Skip to main content
Version: 3.8

Manage Data Recording

The TH API Manager allows users to create scripts based on templates to log data for each resource/operation. The script can manipulate requests and responses, including payloads and header information, by adding, removing, or hiding specific data.

Refer to the table at the conclusion of this subject for more information on data recording methods.

Data Recording Methods

The following are the masking methods used in data recording.

MethodDescription
maskJsonRequestBody()Mask JSON request body
maskJsonResponseBody()Mask JSON response body
maskRestXmlRequestBody()Mask REST XML request body
maskRestXmlResponseBody()Mask REST XML response body
maskRequestBody()Mask SOAP request body
maskResponseBody()Mask SOAP response body

Helper Methods Used

  1. modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText).

This method is used to mask the JSON body.

ParameterDescription
jsonBodyJSON Body obtained from the code
jsonPathJsonPath indicating the key whose value should be masked
replaceTextThe replace value used to mask
  1. partialMaskingUsingJsonPath(jsonBody, jsonPath, startLen, endLen, maskUnmask).

This method is used to partially mask JSON data.

ParameterDescription
jsonBodyJSON Body can be obtained from the code using transactionRecording.getXmlBody()
jsonPathJsonPath indicating the key whose value should be masked
startLenNumber of starting characters in the jsonPath value to be masked/unmasked
endLenNumber of last characters in the jsonPath value to be masked/unmasked
maskUnmaskIndicates whether to mask or unmask the number of characters specified in the above two parameters
  1. modifyElementUsingXPath(xmlBody, xpath, replaceText,namespace).

This method is used to mask the REST XML and SOAP body.

ParameterDescription
xmlBodyxmlBody can be obtained from the code
xpathXPath indicating the key whose value should be masked
replaceTextThe replace value used to mask
namespaceThe namespaceURI if the xpath contains namespace prefix. If there is no namespace prefix in the xpath, then this field can be empty or null. If the xpath contains multiple namespace prefixes, then comma-separated namespaceURI should be given. The format for this field is - namespace = prefix1=namespaceUri1,prefix2=namespaceUri2
info

If no replace text is provided, the value in the x-path will be replaced with The number of stars will based on the length of the value.

  1. partialMaskingUsingXPath(xmlBody, xpath, namespace, startLen, endLen, maskUnmask).

This method is used to mask REST XML and SOAP XML data partially.

ParameterDescription
xmlBodyxmlBody can be obtained from the code using transactionRecording.getXmlBody()
xpathThe path should indicate the key whose value should be masked
namespaceThe namespaceURI if the xpath contains namespace prefix. If there is no namespace prefix in the xpath, then this field can be empty or null. If the xpath contains multiple namespace prefixes, then comma-separated namespaceURI should be given. The format for this field is namespace = prefix1=namespaceUri1,prefix2=namespaceUri2
startLenNo. of starting characters in the XPath value to be masked/unmasked
endLenNo. of last characters in the XPath value to be masked/unmasked
maskUnmaskIndicates whether to mask or unmask the no. of characters specified in the above two parameters
info
  • If the value of the parameter maskUnmask is mask, the characters indicated by startLen and endLen will be masked with *, while the other characters in the value will be unmasked.

  • If the parameter maskUnmask is set to unMask, the characters given by startLen and endLen will be unmasked, while the remaining characters will be masked with *.

Additionally, the following helper methods can be used for masking in data recording:

Method nameMethod DescriptionParameterParameter Description
modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText)This method is used to mask JSON body.jsonBodyJson Body can be obtained from the code.
jsonPathThe path should indicate the key whose value should be masked.
replaceTextThe replace value used to mask.
modifyElementUsingXPath(xmlBody, xpath, replaceText)This method is used to mask REST XML body and SOAP body.xmlBodyxmlBody can be obtained from the code.
xpathThe path should indicate the key whose value should be masked.
replaceTextThe replace value used to mask.
info

If the xpath contains a namespace prefix, add the relevant namespaceURI to the gateway.properties file.

To add a namespace URI in the gateway.properties file, use the syntax prefix=namespaceURI.

Data Recording Sample Scripts

var obj = new Object();

//to mask json request body
obj.maskJsonRequestBody = function(transactionRecording){

var maskedJsonBody;
var jsonBody = transactionRecording.getXmlBody();
var jsonPath = "$..BSOID";
var replaceText = "XXXXXXXXXX";
if(jsonBody != "" && jsonPath != ""){
maskedJsonBody = transactionRecording.modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText);
transactionRecording.setXmlBody(maskedJsonBody);
}

return transactionRecording;
}

//to mask json response body
obj.maskJsonResponseBody = function(transactionRecording){

var maskedJsonBody;
var jsonBody = transactionRecording.getXmlBody();
var jsonPath = "$..ERROR_CODE";
var replaceText = "XXXXXXXXXX";
if(jsonBody != "" && jsonPath != ""){
maskedJsonBody = transactionRecording.modifyElementUsingJsonPath(jsonBody, jsonPath, replaceText);
transactionRecording.setXmlBody(maskedJsonBody);
}

return transactionRecording;
}

//to mask soap request body
obj.maskRequestBody = function(transactionRecording){

var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bss:Provision_Network_Response";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}


return transactionRecording;
}

//to mask soap response body
obj.maskResponseBody = function(transactionRecording){
var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bss:ERROR_CODE";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}
return transactionRecording;
}

//to mask rest xml request body
obj.maskRestXmlRequestBody = function(transactionRecording){

var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bsse:STATUS_CODE";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}


return transactionRecording;
}

//to mask rest xml response body
obj.maskRestXmlResponseBody = function(transactionRecording){
var maskedxmlBody;
var xmlBody = transactionRecording.getXmlBody();
var xpath = "//bsse:RESULT_STATUS";
var replaceText = "XXXXXXXXXX";
if(xmlBody != "" && xpath != ""){
maskedxmlBody = transactionRecording.modifyElementUsingXPath(xmlBody, xpath, replaceText);
transactionRecording.setXmlBody(maskedxmlBody);
}
return transactionRecording;
}

Add Data Recording

info

If REST API is selected, the resource name is displayed. If SOAP API is selected, the operation name is displayed.

  1. Navigate to the REST/SOAP API's Data Recording tab.

The Screen appears as shown below.

datarecording

  1. Click Add Script.

Resource/Operation Level - Data Recording Script dialog box appears as shown below.

  1. Enter the Script.

  2. Click Submit.

The application transfers you to the Data Recording screen.

  1. Click Save as Draft.

datarecording2

On saving, the confirmation message appears as shown below.

datarecording3